<template>
  <base-breadcrumb>
    <searchData :search-data="searchArr" @search="search" />
    <a-card>
      <div class="table-operator">
        <a-button v-btnPermission="'hse_040_add_01'" type="primary" @click="handleUpdate('add', {})" v-if="hideBuquBtn()">新增</a-button>
        <div class="pub-table-select-count mt20">
          <a-icon
            type="info-circle"
            theme="twoTone"
          />
          罚款金额：<a href="">{{ statistics }}</a>元
        </div>
      </div>

      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
      >
        <template slot="sort" slot-scope="text, record, index">{{ index + 1 }}</template>
        <template slot="actions" slot-scope="text, record">
          <MoreButton>
            <a v-btn-permission="'hse_040_loo_04'" @click="handleUpdate('look', record)">查看</a>
            <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
              <a v-btn-permission="'hse_040_edi_02'" @click="() => handleUpdate('edit', record)" v-if="hideBuquBtn()">编辑</a>
            </template>
            <template v-if="record.auditStatus !== 'SUBMITTED'">
              <a v-btn-permission="'hse_040_del_03'" @click="() =>handleUpdate('del', record)" v-if="hideBuquBtn()">删除</a>
            </template>
            <approval-button v-btn-permission="'hse_040_loo_04'" :id="record.id" :status="record.auditStatus"
                             v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'REVOKEIN' || record.auditStatus === 'REVOKE' || record.auditStatus === 'ABOLISH' || record.auditStatus === '1' || record.auditStatus === '3' || record.auditStatus === 'COMMIT'|| record.auditStatus === '2' " />
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import listStatus from '@/components/list_status/meeting_status'
import Api from '@/api/safetySupervision/safeProductAwardPunish/fineForBreachOfContract'


export default {
  name: 'a' + Date.now(),
  components: {
    listStatus
  },
  data() {
    return {
      columns: [
        { title: '序号', dataIndex: 'sort', scopedSlots: { customRender: 'sort' }, width: 70 },
        // { title: '所属分公司', dataIndex: 'branchComName', width: 120 },
        // { title: '所属项目', dataIndex: 'projectName', width: 150 },
        { title: '签发单位', dataIndex: 'signOrgName', width: 250 },
        { title: '罚款类型', dataIndex: 'penaltyTypeStr', width: 150 },
        { title: '被处罚单位/对象', dataIndex: 'penaltyName', width: 150 },
        { title: '罚款金额（元）', dataIndex: 'penaltyAmount', width: 150 },
        { title: '罚款时间', dataIndex: 'penaltyDate', width: 150 },
        { title: '填报人', dataIndex: 'creatorName', width: 150 },
        { title: '填报时间', dataIndex: 'submitDate', width: 150 },
        { title: '状态', dataIndex: 'auditStatusStr', width: 100 },
        { title: '操作', dataIndex: 'actions', width: 220, fixed: 'right', scopedSlots: { customRender: 'actions' } }
      ],
      searchArr: [
        // {
        //   name: '所属单位',
        //   valueKey: 'searchQuery',
        //   type: OrgTreeSelect,
        // },
        // { name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany },
        // { name: '所属项目', keyValue: 'branchComId', valueKey: 'projectId', type: SelectProject },
        { name: '签发单位', value: 'signOrgName', type: 'input' },
        {
          name: '罚款类型', value: 'penaltyType', type: 'select', data: [
            { value: 0, label: '内部单位' },
            { value: 1, label: '外部单位' },
            { value: 2, label: '个人' }
          ]
        },
        { name: '被处罚单位', value: 'penaltyName', type: 'input' },
        { name: '罚款时间', value: 'penaltyDate', type: 'dateRangeFormat' },
        { name: '填报人', value: 'creatorName', type: 'input' },
        { name: '填报时间', value: 'submitDate', type: 'dateRangeFormat' },
        {
          name: '状态',
          value: 'auditStatus',
          type: 'select',
          data: this.STATUS
        }
      ],
      queryParam: {},
      statistics: 0,
      loadData: p => {
        let q = Object.assign(p, { query: this.queryParam })
        Api.findListByCount(q).then(res => {
          if (res.code === this.SUCCESS_CODE) {
            this.statistics = res.data
          }
        })
        return Api.findListByMain(q)
      }
    }
  },
  methods: {
    //搜索
    search(val = {}) {
      this.queryParam = val
      this.$refs.table.refresh(true)
    },

    // 处理更新操作（新增、编辑）
    async handleUpdate(type, data = {}) {
      if (type === 'del') {
        this.$delList2(Api.deleteByMain, this.$refs.table.refresh, { ids: [data.id] })
      } else {
        this.$router.push({
          name: 'fineForBreachOfContractAdd',
          query: {
            id: data.id || '',
            pageType: type
          }
        })
      }
    }
  }
}
</script>
